<?php
session_start();
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

//public nodo
//public CboNodo
$CboNodo = $_REQUEST["CboNodo"];
$pageaction = "solotrn_IngresarPerfil.php";
//''TopNodo = ObtenerPrimerNodosql
//''if CboNodo = "" then CboNodo = TopNodo	'si es blanco le asigno el primer valor
//''StrCboNodo = Cargar_nodo_usuariosql(CboNodo, "CboNodo", " style='width:226' onChange='frm.submit();'")
$TopNodo = 1;
if (empty($CboNodo)) $CboNodo = $TopNodo;	//'si es blanco le asigno el primer valor
$strsql = "select * from solotb_nivel1";
SoloFun_ExecSql ($strsql, $SoloArrNodos);
$StrCboNodo = SoloFun_CargaCombo($SoloArrNodos,"CboNodo","$CboDisabled",$itemselec," class='SoloStyle_Texto' style='width:200'","");

//   'rw "",$_REQUEST["hidGraba")
if ($_REQUEST["hidGraba"] == "S") {
    $strSql = "insert into solotb_perfil values (";
    $strSql .= $_REQUEST["HidId"].",'";
    $strSql .= strtoupper($_REQUEST["ATxtDesc"]) . "',";
    $strSql .= $_REQUEST["CboNodo"] . ")";
    //'response.write "<br>strSql="&strSql
    //  're
    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
    if($oConexion->EjecutarQuery($strSql)) {
        $oConexion->Cerrar();
        //'      set ObjGraba=nothing
        //printArray($_REQUEST["transaccion"]);
        foreach ($_REQUEST["transaccion"] as $key) {
            $arrSplit = preg_split("[\@]", $key);
            $strSql = "insert into solotb_perfil_modulo values (";
            $strSql .=  $_REQUEST["HidId"] . ",";
            $strSql .=  $arrSplit[0]. ",";
            $strSql .=  $arrSplit[1]. ",";
            $strSql .=  $_REQUEST["CboNodo"] . ")";

            $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
                    $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
            if(!$oConexion->EjecutarQuery($strSql)) {
                $strMsg="?SoloError=1&CboNodo=".$CboNodo;
                echo $oConexion->getErrorMessage();
                $oConexion->Cerrar();
                break;
            }else
                $strMsg="?SoloError=0&CboNodo=".$CboNodo;
            $oConexion->Cerrar();
            //echo $strMsg;
            //'response.write strSQL & "<br>"
        }
//    if(!is_null($strMsg) && !empty($strMsg))
//        header ("Location: $strMsg");
    }else {
        echo $oConexion->getErrorMessage();
        $oConexion->Cerrar();
    }
}

$MaxId = SoloFun_Maximo("co_perf","solotb_perfil");
//'   rw "",MaxId

$strSql = "select * from solotb_modulo where nodo = $CboNodo order by co_modu";
$oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
        $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);

$bandMod = false;
if (!$oConexion->EjecutarQuery($strSql)) {
    $strERROR = 1;
    echo $oConexion->getErrorMessage();
    $err = 0;
}else {
    $bandMod=true;
    $arrModulos = $oConexion->getData("NUM");
}
//'response.write "<br>tofil = " & ubound(arrModulos,2)
$oConexion->liberarResultado();
$oConexion->Cerrar();
?>
<html>
    <head>
        <title>MIES-WORKFLOW</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="SoloStyles/Solostyles.css" type="text/css">
        <SCRIPT type="text/JavaScript" src="Includes/Solofun_generales.js"></SCRIPT>
        <SCRIPT type="text/JavaScript" src="PHPMailer/fun_generales.js"></SCRIPT>
    </head>

    <body topmargin=0 leftmargin=0 onkeydown="checkKey();">
        <img src="templates/SoloTemplate_LogoCabecera.png" style="height: 50px"/>
        <!-- Include File="Includes/solotrn_header.asp" -->
        <p align="center" class="SoloStyle_TituloPaginas">Ingresar Perfiles</p>
        <form name="frm" action="solotrn_IngresarPerfil.php" method="POST">
            <input name="hidGraba" size="5" type="hidden" class="texto" value="S">
            <table border="0" width="80%" align="center" cellpadding="2" cellspacing="1" bordercolor="#CCCCCC">
                <tr>
                    <td>
                        <img src="iconos/soloico_salir.gif" border="1" alt="Regresar" style="cursor:hand" onClick="javascript: window.opener.location.reload(); window.close();" >
                        <img src="iconos/soloico_grabar.gif" border="1" alt="Grabar Perfil" style="cursor:hand" onClick="frm.submit();">
                    </td>
            </table>
            <table border="0" width="80%" align="center" bordercolor="#CCCCCC" cellpadding="2" cellspacing="1">
                <tr>
                    <td class="SoloStyle_Etiqueta">Subsecretar&iacute;a/Dir. Provincial</td>
                    <td class="SoloStyle_EtiquetaCajas"><?php echo $StrCboNodo; ?></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Id</b></td>
                    <td class="SoloStyle_EtiquetaCajas"><?php echo $MaxId;?><input type="hidden" maxlenght="50" size="50" name="HidId" class="texto" value="<?php echo $MaxId;?>"></td>
                </tr>
                <tr>
                    <td class="SoloStyle_Etiqueta"><b>Descripci&oacute;n</b></td>
                    <td class="SoloStyle_EtiquetaCajas">
                        <input type="text" maxlenght="50" size="43" name="ATxtDesc" class="SoloStyle_Texto"></td>
                </tr>
            </table>
            <?php $looper = 0;
            if ($bandMod) { ?>
            <table width="90%" border="1" cellpadding="0" cellspacing="1" align="center" bordercolor="#CCCCCC">
                    <?php for ($i = 0; $i < count($arrModulos); $i++) {
                        if ($looper == 0) {?>
                <!-- crea una nueva fila para 2 modulos-->
                <tr><td width="50%" valign="top" class="SoloStyle_grid">
                                    <?php }else { ?>
                        <!-- crea la segunda columna de la fila-->
                    <td width="50%" valign="top" class="SoloStyle_grid">
                                    <?php }?>
                        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="SoloStyle_grid">
                            <tr> 

                                <td colspan="2" class="SoloStyle_Etiqueta" height="20">&nbsp;&nbsp;<?php echo $arrModulos[$i][1];?></td>
                            </tr>
                                    <?php
                                    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"],
                                            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
                                    $strSql = "select * from solotb_modulo_transaccion where nodo=$CboNodo and co_modu={$arrModulos[$i][0]}";
//'rw "",strsql
//'re
//ObjTran.Open strSql,Session("SoloConn")
                                    $numFil=-1;
                                    $bandPerfil=false;

                                    if (!$oConexion->EjecutarQuery($strSql)) {
                                        $strERROR = 1;
                                        $err = 0;
                                    }else {
                                        $bandPerfil=true;
                                        $arrTransacciones = $oConexion->getData("NUM");
                                        $numFil = count($arrTransacciones);
                                    }
                                    ?>
                            <tr>
                                <td>
                                            <?php if ($bandPerfil) { ?>
                                                <?php for ($j = 0; $j < count($arrTransacciones); $j++) {?>
                                    <input name="transaccion[]" type="checkbox" id="transaccion" value="<?php echo $arrModulos[$i][0];?>@<?php echo $arrTransacciones[$j][1];?>"/>
                                    &nbsp;&nbsp;<?php echo $arrTransacciones[$j][2];?><br>
                                                    <?php }
                                            } ?>
                                </td>
                            </tr>
                        </table>

                                <?php if ($looper == 1) {?>
                        <!-- cierra columna 2 de la fila y cierra la fila-->
                    </td></tr>
                            <?php $looper = 0;?>
                            <?php }else {?>
                <!-- cierra columna 1 de la fila-->
                </td>
                            <?php $looper = 1;?>
                            <?php }?>
                        <?php }?>
                    <?php if ($looper == 1) {?>
                &nbsp;</tr>
                        <?php }?>
            </table>
                <?php } ?>
            <br>
        </form>
    </body>
</html>
<?php
include "Includes/soloFun_ShowMessages.php";
?>